package com.sais.manage.boot.daily.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sais.common.entity.Result;
import com.sais.manage.boot.daily.dto.BuildingChartDTO;
import com.sais.manage.boot.daily.dto.SanitationDTO;
import com.sais.manage.boot.daily.dto.SanitationSaveDTO;
import com.sais.manage.boot.daily.dto.SanitationSearchDTO;
import com.sais.manage.boot.daily.service.ISanitationService;
import com.sais.manage.boot.platform.utils.ShiroUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 宿舍管理系统-卫生信息 controller 类
 *
 * @author zwp
 * @date 2020/2/2
 **/
@Api(tags = "卫生信息管理")
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/api/daily/sanitation")
public class SanitationController {

    @Resource
    private ISanitationService sanitationService;

    @ApiOperation("卫生信息 保存")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Result saveSanitation(@RequestBody SanitationSaveDTO sanitationSaveDTO) {
        sanitationService.saveSanitation(sanitationSaveDTO);
        return new Result();
    }

    @ApiOperation("卫生信息 删除")
    @RequestMapping(value = "/delete/{sanitationId}", method = RequestMethod.GET)
    public Result deleteSanitation(@PathVariable("sanitationId") String sanitationId) {
        sanitationService.deleteSanitation(sanitationId);
        return new Result();
    }

    @ApiOperation("根据id 查询 卫生信息")
    @RequestMapping(value = "/select/{sanitationId}", method = RequestMethod.GET)
    public Result selectSanitation(@PathVariable("sanitationId") String sanitationId) {
        SanitationDTO sanitation = sanitationService.selectSanitation(sanitationId);
        return new Result().data("sanitation", sanitation);
    }

    @ApiOperation("分页条件 查询")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Result listSanitation(@RequestParam(defaultValue = "1") Integer current,
                                 @RequestParam(defaultValue = "30") Integer size,
                                 SanitationSearchDTO searchDTO) {
        Page<SanitationDTO> page = sanitationService.listSanitation(current, size, searchDTO);
        Map<String, Integer> countColumn = sanitationService.CountColumn(searchDTO);
        List<Map> buildCountColumn = sanitationService.buildCountColumn(searchDTO);
        return new Result().data("sanitations", page).data("countColumn", countColumn).data("buildCountColumn", buildCountColumn);
    }

    @ApiOperation("根据管理人员id 查询该管理人员管理的宿舍楼卫生统计列表")
    @RequestMapping(value = "/list/manage", method = RequestMethod.GET)
    public Result listSanitationByManage(@RequestParam(defaultValue = "1") Integer current,
                                         @RequestParam(defaultValue = "30") Integer size,
                                         SanitationSearchDTO searchDTO) {
        String userId = ShiroUtils.getLoginUser().getUkId();
        Page<SanitationDTO> page = sanitationService.listSanitationByManage(current, size, searchDTO, userId);
        return new Result().data("sanitations", page);
    }

    @ApiOperation("查询 当前管理员管理宿舍楼的所有房间卫生分数集合")
    @RequestMapping(value = "/list/score/manage", method = RequestMethod.GET)
    public Result listScoreByManage() {
        String userId = ShiroUtils.getLoginUser().getUkId();
        List<Integer> scores = sanitationService.listScoreByManage(userId);
        return Result.response().data("scores", scores);
    }

    @ApiOperation("查询 每栋宿舍楼大于80的房间数")
    @RequestMapping(value = "/list/score/building", method = RequestMethod.GET)
    public Result listCountBeyondScoreByBuilding() {
        List<BuildingChartDTO> buildingCharts = sanitationService.listCountBeyondScoreByBuilding();
        return Result.response().data("buildingCharts", buildingCharts);
    }

    @ApiOperation("统计卫生柱图")
    @RequestMapping(value = "/column", method = RequestMethod.GET)
    public Result listColumn() {
        List<BuildingChartDTO> buildingCharts = sanitationService.listCountBeyondScoreByBuilding();
        return Result.response().data("buildingCharts", buildingCharts);
    }




}
